package com.avamanager.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.avamanager.common.annotation.Log;
import com.avamanager.common.core.controller.BaseController;
import com.avamanager.common.core.domain.AjaxResult;
import com.avamanager.common.enums.BusinessType;
import com.avamanager.app.domain.AppRewardPunishment;
import com.avamanager.app.service.IAppRewardPunishmentService;
import com.avamanager.common.utils.poi.ExcelUtil;
import com.avamanager.common.core.page.TableDataInfo;

/**
 * 奖惩信息Controller
 * 
 * @author FenvyYe
 * @date 2022-08-15
 */
@RestController
@RequestMapping("/app/reward_punishment")
public class AppRewardPunishmentController extends BaseController
{
    @Autowired
    private IAppRewardPunishmentService appRewardPunishmentService;

    /**
     * 查询奖惩信息列表
     */
    @PreAuthorize("@ss.hasPermi('app:reward_punishment:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppRewardPunishment appRewardPunishment)
    {
        startPage();
        List<AppRewardPunishment> list = appRewardPunishmentService.selectAppRewardPunishmentList(appRewardPunishment);
        return getDataTable(list);
    }

    /**
     * 导出奖惩信息列表
     */
    @PreAuthorize("@ss.hasPermi('app:reward_punishment:export')")
    @Log(title = "奖惩信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppRewardPunishment appRewardPunishment)
    {
        List<AppRewardPunishment> list = appRewardPunishmentService.selectAppRewardPunishmentList(appRewardPunishment);
        ExcelUtil<AppRewardPunishment> util = new ExcelUtil<AppRewardPunishment>(AppRewardPunishment.class);
        util.exportExcel(response, list, "奖惩信息数据");
    }

    /**
     * 获取奖惩信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:reward_punishment:query')")
    @GetMapping(value = "/{rewardPunishmentId}")
    public AjaxResult getInfo(@PathVariable("rewardPunishmentId") Long rewardPunishmentId)
    {
        return AjaxResult.success(appRewardPunishmentService.selectAppRewardPunishmentByRewardPunishmentId(rewardPunishmentId));
    }

    /**
     * 新增奖惩信息
     */
    @PreAuthorize("@ss.hasPermi('app:reward_punishment:add')")
    @Log(title = "奖惩信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppRewardPunishment appRewardPunishment)
    {
        return toAjax(appRewardPunishmentService.insertAppRewardPunishment(appRewardPunishment));
    }

    /**
     * 修改奖惩信息
     */
    @PreAuthorize("@ss.hasPermi('app:reward_punishment:edit')")
    @Log(title = "奖惩信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppRewardPunishment appRewardPunishment)
    {
        return toAjax(appRewardPunishmentService.updateAppRewardPunishment(appRewardPunishment));
    }

    /**
     * 删除奖惩信息
     */
    @PreAuthorize("@ss.hasPermi('app:reward_punishment:remove')")
    @Log(title = "奖惩信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rewardPunishmentIds}")
    public AjaxResult remove(@PathVariable Long[] rewardPunishmentIds)
    {
        return toAjax(appRewardPunishmentService.deleteAppRewardPunishmentByRewardPunishmentIds(rewardPunishmentIds));
    }
}
